import tkinter as tk
import pub

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        self.txtTopic = tk.Entry(self)
        self.txtTopic.insert(0, "home/ir/1")
        self.txtTopic.pack(side = "top")

        self.btnOn = tk.Button(self)
        self.btnOn["text"] = "AC ON"
        self.btnOn["command"] = self.onOn
        self.btnOn.pack(side = "top")

        self.hi_there = tk.Button(self)
        self.hi_there["text"] = "AC OFF"
        self.hi_there["command"] = self.onOff
        self.hi_there.pack(side="top")

        self.txtMac = tk.Entry(self)
        self.txtMac.insert(0, "f0:2f:74:dd:98:96")
        self.txtMac.pack(side = "top")

        self.btnWakeup = tk.Button(self)
        self.btnWakeup["text"] = "WakeupPC"
        self.btnWakeup["command"] = self.wakeupPC
        self.btnWakeup.pack(side="top")


        self.quit = tk.Button(self, text="QUIT", fg="red",
                              command=self.master.destroy)
        self.quit.pack(side="bottom")

    def onOff(self):
        # print("hi there, everyone!")
        topic = self.txtTopic.get()
        pub.gree_ac(topic, 'off')

    def onOn(self):
        topic = self.txtTopic.get()
        pub.gree_ac(topic, 'on')

    def wakeupPC(self):
        topic = self.txtTopic.get()
        mac = self.txtMac.get()
        pub.wakeupPC(topic, mac)

root = tk.Tk()
root.geometry("320x200")
app = Application(master=root)
app.mainloop()
